package com.damon.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.damon.common.ResultModel;
import com.damon.service.WcsHttpService;
import com.damon.utils.JsonChangeUtils;

@RestController
@RequestMapping("/wcs")
public class WcsHttpController {
	private static Logger logger = LoggerFactory.getLogger(WcsHttpController.class);
	
	@Autowired
	WcsHttpService wcsHttpService;
	
	/**
	 * 下发任务接口1
	 * @param request
	 * @param response
	 * @param json
	 * @return
	 */
	@RequestMapping(value = "/task_i",method = RequestMethod.POST,produces="application/json;charset=UTF-8")
	public String wcsPost(HttpServletRequest request,HttpServletResponse response,@RequestBody(required=false) String json) {
		long startTime = System.currentTimeMillis();
		//url=wcs/task_i
		String url = request.getServletPath();
		logger.info("wms调用url："+url+",参数："+json);
		String result = wcsHttpService.doProcedure(url, json);
		logger.info("返回给wms的结果："+result);
		logger.info("请求耗时："+ (System.currentTimeMillis() - startTime)+"ms!!\n");
		return result;
	}
	
	@RequestMapping(value = "/task_ii",method = RequestMethod.POST,produces="application/json;charset=UTF-8")
	public String wcsPostTask2(HttpServletRequest request,HttpServletResponse response,@RequestBody(required=false) String json) {
		long startTime = System.currentTimeMillis();
		//url=wcs/task_i
		String url = request.getServletPath();
		logger.info("wms调用url："+url+",参数："+json);
		String result = wcsHttpService.doProcedure(url, json);
		logger.info("返回给wms的结果："+result);
		logger.info("请求耗时："+ (System.currentTimeMillis() - startTime)+"ms!!\n");
		return result;
	}
}
